@extends('admin.layout')
@section('content')

    <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main" >
        <div class="col-md-12" id="content" >
            <div class="app_content_div" id="app_content_div_301Index">
                <h3>修改专家</h3>
            </div>
                <form class="form-horizontal" method="post" action="/adm/expert">
                    {{csrf_field()}}
                    <input name="_token" type="hidden" value="">
                    <div class="form-group">
                        <label for="name" class="col-sm-2 control-label"><span style="color:red;"></span>专家</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" style="width:300px;" id="name" name="name" value=" {{$Expert->name}}">
                        </div>
                    </div>
                    <div class="form-group">
                    <label for="upload_file" class="col-sm-2 control-label"><span style="color:red;"></span>缩略图</label>
                    <div class="col-sm-10">
                        <input  id="image" name="image"  type="file"  onchange="saveThumb()"/>
                        <div id="image-container" style="height: 200px;width: 200px" ><img style="height: 200px;width: 200px" src="{{$Expert->image}}"></div>
                    </div>
                    </div>
                    <div class="form-group">
                        <label for="info" class="col-sm-2 control-label"><span style="color:black;">科室</span></label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" style="width:300px;" id="ks" name="ks"value=" {{$Expert->ks}} ">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="info" class="col-sm-2 control-label"><span style="color:black;">职称</span></label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" style="width:300px;" id="zc" name="zc"value=" {{$Expert->zc}} ">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="info" class="col-sm-2 control-label"><span style="color:black;">医院</span></label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" style="width:300px;" id="hos" name="hos"value=" {{$Expert->hos}} ">
                        </div>
                    </div>
                    <div class="form-group" >
                        <label for="intro" class="col-sm-2 control-label"><span style="color:red;"></span>简介</label>
                        <div class="col-sm-10">
                            <script id="intro" name="intro" type="text/plain">{{$Expert->intro}}</script>
                            <script type="text/javascript">
                                var editor = UE.getEditor('intro')
                            </script>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-offset-2 col-sm-10">
                            {{--                    <button type="button"  onclick="update()"  class="btn btn-default">确定</button>--}}
                            <button type="button" onclick="update()" class="btn btn-default">确定</button>

                        </div>
                    </div>

                </form>

                <script>
                    function saveThumb() {
                        var file = document.getElementById("image").files[0];
                        var reader = new FileReader();
                        reader.onload = function(e) {
                            var img = document.createElement("img");
                            img.src = e.target.result;
                            img.width = 200;
                            img.height = 200;
                            var container = document.getElementById('image-container');
                            while (container.firstChild) {
                                container.removeChild(container.firstChild);
                            }
                            // 添加新的图片
                            container.appendChild(img);
                            alert("上传成功！")
                        }

                        reader.readAsDataURL(file);
                    }
                    function update()
                    {
                        var name=$('#name').val();
                        var ks=$('#ks').val();
                        var zc=$('#zc').val();
                        var hos=$('#hos').val();
                        let intro=editor.getContentTxt();
                        $.ajaxFileUpload({
                            url:'/adm/expert/edit/{{$Expert->id}}',
                            type:'post',
                            dataType:'json',
                            data:{
                                'name':name,
                                'ks':ks,
                                'zc':zc,
                                'hos':hos,
                                'intro':intro,
                                '_token': '{{csrf_token()}}'
                            },
                            success: function (data) {
                                if (data.success) {
                                    alert(data.msg);
                                    location.href = '/adm/expert';
                                } else {
                                    alert(data.msg);
                                }
                            }
                        });
                    }
                </script>

@endsection
